//==========================================================================
// Copyright (c) 2000-2006,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include "util.h"

int s3c2410_usb_open( const char * client );
int s3c2410_usb_start( void );
void usb_soft_connect(int enable);
void usb_enumerate(void);
void usb_device_open(void);
void dump_udcreg(void);


int usb_eth_init(u32 base);
int usb_eth_tx(u8 *outbuf, int size);
int usb_eth_rx(u8 *inbuf, int size);
int pxa_usb_stop( void );

extern void InitElrUser()
{
    dump_udcreg();
    s3c2410_usb_open("usb serial");
    s3c2410_usb_start();
    usb_soft_connect(1);
    usb_enumerate();
    usb_device_open();
}

extern unsigned int ElrUDCWrite(char *pTxBuffer, unsigned int BufLen)
{
    return s3c2410_usb_send(pTxBuffer, BufLen);
}


extern unsigned int ElrUDCRead(char *pRxBuffer, unsigned int Bufflen)
{
    return s3c2410_usb_recv(pRxBuffer, Bufflen);
}

//return 0 :  time out
extern unsigned int ElrUDCReadTO(char *pRxBuffer, unsigned int Bufflen, unsigned long TimeOut)
{
    unsigned int num;
    while (1) {
        num = s3c2410_usb_recv(pRxBuffer, Bufflen);
        if (num) {  //if received valid data, break
            break;
        }
    }
//    printk("ElrUDCReadTO wanted %d, actul get %d\n", Bufflen, num);
    return num;
}

extern int elr_usb_close( void )
{
    s3c2410_usb_stop();
    return 0;
}
